package servlet.discussion;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.control.DiscussionMgr;
import bean.entity.Discussion;

@SuppressWarnings("serial")
public class DiscussionContentServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Discussion> disList = DiscussionMgr.queryAllDiscussionOrderByTime();
		
		req.setAttribute("disList", disList);
		req.getRequestDispatcher("./discussion/discussionContent.jsp").forward(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		HttpSession session = req.getSession();
		String question = req.getParameter("question");
		String memId = (String)session.getAttribute("memId");
		
		DiscussionMgr.addDiscussion(question, Long.parseLong(memId));
	}
}
